<?php

if (!defined("EXPONENT")) exit("");

if (exponent_permissions_check("configure",$loc)) {
	if (isset($_GET['id']))
		$id=intval($_GET['id']);
	else
		exponent_flow_redirect();
	
	$playlist=exponent_sessions_getTicketString();
	$pl=$db->selectObject('present_playlist','session = "' . $playlist .'"');
	if ($pl==null)
		exponent_flow_redirect();
	else
	{
		//update create_time
		$pl->create_time=time();
		$db->updateObject($pl,"present_playlist");
	}
	
	// cannot use switchValues, we must write it by hand
	$a=intval($_GET['a']); $b=intval($_GET['b']);
	//$db->switchValues('present_playlist_songs', 'rank', intval($_GET['a']), intval($_GET['b']), "playlist_id = ".  $pl->id);
	$object_a = $db->selectObject('present_playlist_songs',"rank = {$a} AND playlist_id = ".  $pl->id);
	$object_b = $db->selectObject('present_playlist_songs',"rank = {$b} AND playlist_id = ".  $pl->id);

	if ($object_a && $object_b) {
		$tmp = $object_a->rank;
		$object_a->rank = $object_b->rank;
		$object_b->rank = $tmp;

		$db->updateObject($object_a,'present_playlist_songs',"song_id = " . $object_a->song_id);
		$db->updateObject($object_b,'present_playlist_songs',"song_id = " . $object_b->song_id);
	}
	exponent_flow_redirect();
} else {
	echo SITE_403_HTML;
}

?>
